package alik.notes.server.persistence;

import java.util.List;

import javax.jdo.PersistenceManager;

import alik.notes.shared.data.Note;

public class NotesPersistence {

	@SuppressWarnings("unchecked")
	public static List<Note> queryNotes(String userId) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
	    String query = "select from " + NotePersistable.class.getName() + " order by title asc";
	    List<NotePersistable> notes = (List<NotePersistable>) pm.newQuery(query).execute();
		return PersistenceTransformer.transform(notes);
	}
	
	public static void addNote(Note note) {
		note = PersistenceTransformer.transform(note);
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(note);
        } finally {
            pm.close();
        }
	}

}
